#ifndef _SPRITE_BIN_H_
#define _SPRITE_BIN_H_

#include "ui_sprite.h"

namespace ui
{

/****
 * Accelator for drawing many same-layered sprites of similar bitmap type
 */
class SpriteBin
{
public:
	SpriteBin();
	~SpriteBin();

	void				AddSprite(UISprite* pSprite, const math::Vec2& Pos);
	void				AddSprite(UISprite* pSprite, float rot = 0.0f);
	void				AddClippedSprite(UISprite* pSprite, const math::Vec2& Min, const math::Vec2& Max);
	void				Render(const math::Vec2& Offset = math::Vec2(0,0), bool Sort = true);
	void				Render(bool Sort) { Render(math::Vec2(0,0), Sort); }
	void				Reset() { m_SpriteC = 0; };
	bool				IsFull() const { return m_SpriteC >= MAX_SPRITES; };
private:
	static int			SortFunc( const void *arg1, const void *arg2 );
	void				SortSprites();

	struct				SpriteInfo
	{
		UISprite*		pSprite;
		math::Vec2		Pos;
		bool			Clipped, Rotated;
		math::Vec2		ClipMin, ClipMax;
		float			Rot;
	};
	static const int	MAX_SPRITES		=	1000;
	SpriteInfo			m_SpriteA[MAX_SPRITES];
	int					m_SpriteC;
};

}

#endif // _SPRITE_BIN_H_